<?php

use Swoole\Coroutine as Co;

// 异步读取

//4.3的版本移除所有异步模块, 分离异步扩展到 async-ext 移除的异步模块如下:
//Async系列函数
//MySQL
//Redis
//HttpClient
//MemoryPool
//MsgQueue
//RingQueue
//如果要使用请安装async-ext扩展https://github.com/swoole/async-ext
// 第一种用法
//swoole_async_readfile('./read.txt', function ($filename, $content) {
//    echo "filename:$filename" . PHP_EOL;
//    echo $content;
//});

// 第二种用法
// https://www.jianshu.com/p/b620836c461a?tdsourcetag=s_pctim_aiomsg
//go(function () {
//    $filename = './read.txt';
//    echo "filename:$filename" . PHP_EOL;
//    Co::sleep(1);
//    $content = file_get_contents($filename);
//    echo $content;
//});
//
//echo "哈哈哈,你看谁先被打印" . PHP_EOL;

// 第三种用法
// 开启协程 runtime
\Swoole\Runtime::enableCoroutine();
go(function () {
    $filename = './read.txt';
    echo "filename:$filename" . PHP_EOL;
    $content = file_get_contents($filename);
    echo $content;
});

echo "哈哈哈,你看谁先被打印" . PHP_EOL;